package com.prs.crm.action.oa;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.FileUtil;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.Affiche;
import com.prs.crm.domain.oa.Announcement;
import com.prs.crm.domain.oa.AnnouncementReceive;
import com.prs.crm.domain.oa.Comment;
import com.prs.crm.domain.oa.CommentChild;
import com.prs.crm.domain.oa.News;
import com.prs.crm.domain.oa.NewsReceive;
import com.prs.crm.domain.oa.Notice;
import com.prs.crm.domain.oa.NoticeAccept;
import com.prs.crm.domain.oa.PictureNews;
import com.prs.crm.domain.oa.PictureNewsReceive;
import com.prs.crm.service.oa.AnnouncementReceiveService;
import com.prs.crm.service.oa.CommentChildService;
import com.prs.crm.service.oa.CommentService;
import com.prs.crm.service.oa.NewsReceiveService;
import com.prs.crm.service.oa.NewsService;
import com.prs.crm.service.oa.NoticeAcceptService;
import com.prs.crm.service.oa.NoticeService;
import com.prs.crm.service.oa.PictureNewsReceiveService;
import com.prs.crm.service.oa.PictureNewsService;

public class CommentAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private Comment comment;
	private CommentService commentService;
	private Affiche affiche;
	private News news;
	private NewsService newsService;
	private List<CommentChild> childs;
	private CommentChild commentChild;
	private CommentChildService commentChildService;
	private File upload;
	private String uploadFileName;
	private String childNum;
	private PictureNews pictureNews;
	private PictureNewsService pictureNewsService;
	private Announcement announcement;
	private Notice notice;
	private NoticeService noticeService;
	private NewsReceive newsReceive;
	private NewsReceiveService newsReceiveService;
	private PictureNewsReceive pictureNewsReceive;
	private PictureNewsReceiveService pictureNewsReceiveService;
	private NoticeAccept noticeAccept;
	private NoticeAcceptService noticeAcceptService;
	private AnnouncementReceive announcementReceive;
	private AnnouncementReceiveService announcementReceiveService;
	public AnnouncementReceiveService getAnnouncementReceiveService() {
		return announcementReceiveService;
	}
	public void setAnnouncementReceiveService(
			AnnouncementReceiveService announcementReceiveService) {
		this.announcementReceiveService = announcementReceiveService;
	}
	public AnnouncementReceive getAnnouncementReceive() {
		return announcementReceive;
	}
	public void setAnnouncementReceive(AnnouncementReceive announcementReceive) {
		this.announcementReceive = announcementReceive;
	}
	public PictureNewsReceive getPictureNewsReceive() {
		return pictureNewsReceive;
	}
	public void setPictureNewsReceive(PictureNewsReceive pictureNewsReceive) {
		this.pictureNewsReceive = pictureNewsReceive;
	}
	public PictureNewsReceiveService getPictureNewsReceiveService() {
		return pictureNewsReceiveService;
	}
	public void setPictureNewsReceiveService(
			PictureNewsReceiveService pictureNewsReceiveService) {
		this.pictureNewsReceiveService = pictureNewsReceiveService;
	}
	public NewsReceive getNewsReceive() {
		return newsReceive;
	}
	public void setNewsReceive(NewsReceive newsReceive) {
		this.newsReceive = newsReceive;
	}
	public NewsReceiveService getNewsReceiveService() {
		return newsReceiveService;
	}
	public void setNewsReceiveService(NewsReceiveService newsReceiveService) {
		this.newsReceiveService = newsReceiveService;
	}
	@Action("listComment")
	public String listComment() {
		comment=this.commentService.getCommentByNews(news);
		if(comment==null){
			comment=new Comment();
			this.comment.setNews(news);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		childs=this.commentChildService.getChildByComment(comment);
		if(childs.size()>0){
			childNum=String.valueOf(childs.size());
		}else{
			childNum=String.valueOf("0");
		}
		return SUCCESS;
	}
	@Action("listCommentNewsReceive")
	public String listNewsCommentReceive() {
		comment=this.commentService.getCommentByNotice(newsReceive);
		if(comment==null){
			comment=new Comment();
			this.comment.setNewsReceive(newsReceive);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		childs=this.commentChildService.getChildByComment(comment);
		if(childs.size()>0){
			childNum=String.valueOf(childs.size());
		}else{
			childNum=String.valueOf("0");
		}
		return SUCCESS;
	}
	@Action("listCommentPictureNews")
	public String listCommentPictureNews() {
		comment=this.commentService.getCommentByPictureNews(pictureNews);
		if(comment==null){
			comment=new Comment();
			this.comment.setPictureNews(pictureNews);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		childs=this.commentChildService.getChildByComment(comment);
		if(childs.size()>0){
			childNum=String.valueOf(childs.size());
		}else{
			childNum=String.valueOf("0");
		}
		return SUCCESS;
	}
	@Action("listCommentPictureNewsReceive")
	public String listCommentPictureNewsReceive() {
		comment=this.commentService.getCommentByNotice(pictureNewsReceive);
		if(comment==null){
			comment=new Comment();
			this.comment.setPictureNewsReceive(pictureNewsReceive);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		childs=this.commentChildService.getChildByComment(comment);
		if(childs.size()>0){
			childNum=String.valueOf(childs.size());
		}else{
			childNum=String.valueOf("0");
		}
		return SUCCESS;
	}
	@Action("listCommentAnnouncement")
	public String listCommentAnnouncement() {
		comment=this.commentService.getCommentByAnnouncement(announcement);
		if(comment==null){
			comment=new Comment();
			this.comment.setAnnouncement(announcement);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		childs=this.commentChildService.getChildByComment(comment);
		if(childs.size()>0){
			childNum=String.valueOf(childs.size());
		}else{
			childNum=String.valueOf("0");
		}
		return SUCCESS;
	}
	@Action("listCommentAnnouncementReceive")
	public String listCommentAnnouncementReceive() {
		comment=this.commentService.getCommentByNotice(announcementReceive);
		if(comment==null){
			comment=new Comment();
			this.comment.setAnnouncementReceive(announcementReceive);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		childs=this.commentChildService.getChildByComment(comment);
		if(childs.size()>0){
			childNum=String.valueOf(childs.size());
		}else{
			childNum=String.valueOf("0");
		}
		return SUCCESS;
	}
	@Action("listCommentNotice")
	public String listCommentNotice() {
		comment=this.commentService.getCommentByNotice(notice);
		if(comment==null){
			comment=new Comment();
			this.comment.setNotice(notice);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		childs=this.commentChildService.getChildByComment(comment);
		if(childs.size()>0){
			childNum=String.valueOf(childs.size());
		}else{
			childNum=String.valueOf("0");
		}
		return SUCCESS;
	}
	@Action("listCommentNoticeAccept")
	public String listCommentNoticeAccept() {
		comment=this.commentService.getCommentByNotice(noticeAccept);
		if(comment==null){
			comment=new Comment();
			comment.setNoticeAccept(noticeAccept);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		childs=this.commentChildService.getChildByComment(comment);
		if(childs.size()>0){
			childNum=String.valueOf(childs.size());
		}else{
			childNum=String.valueOf("0");
		}
		return SUCCESS;
	}
	@Action("editCommentChild")
	public String editCommentChild() {
		comment=this.commentService.getCommentByNews(news);
		if(comment==null){
			comment=new Comment();
			this.comment.setNews(news);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		return SUCCESS;
	}
	@Action("editCommentChildNewsReceive")
	public String editCommentChildNewsReceive() {
		comment=this.commentService.getCommentByNotice(newsReceive);
		if(comment==null){
			comment=new Comment();
			this.comment.setNewsReceive(newsReceive);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		return SUCCESS;
	}
	@Action("editCommentChildPictureNews")
	public String editCommentChildPictureNews() {
		comment=this.commentService.getCommentByPictureNews(pictureNews);
		if(comment==null){
			comment=new Comment();
			this.comment.setPictureNews(pictureNews);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		return SUCCESS;
	}
	@Action("editCommentChildPictureNewsReceive")
	public String editCommentChildPictureNewsReceive() {
		comment=this.commentService.getCommentByNotice(pictureNewsReceive);
		if(comment==null){
			comment=new Comment();
			this.comment.setPictureNewsReceive(pictureNewsReceive);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		return SUCCESS;
	}
	@Action("editCommentChildAnnouncement")
	public String editCommentChildAnnouncement() {
		comment=this.commentService.getCommentByAnnouncement(announcement);
		if(comment==null){
			comment=new Comment();
			this.comment.setAnnouncement(announcement);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		return SUCCESS;
	}
	@Action("editCommentChildAnnouncementReceive")
	public String editCommentChildAnnouncementReceive() {
		comment=this.commentService.getCommentByNotice(announcementReceive);
		if(comment==null){
			comment=new Comment();
			this.comment.setAnnouncementReceive(announcementReceive);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		return SUCCESS;
	}
	@Action("editCommentChildNotice")
	public String editCommentChildNotice() {
		comment=this.commentService.getCommentByNotice(notice);
		if(comment==null){
			comment=new Comment();
			this.comment.setNotice(notice);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		return SUCCESS;
	}
	@Action("editCommentChildNoticeAccept")
	public String editCommentChildNoticeAccept() {
		comment=this.commentService.getCommentByNotice(noticeAccept);
		if(comment==null){
			comment=new Comment();
			this.comment.setNoticeAccept(noticeAccept);
			Person p = AppContext.getAccountContext().currentUser();
			this.comment.setPerson(p);
			this.commentService.save(comment);
		}
		return SUCCESS;
	}
	@Action(value = "saveChild", results = {
			@Result(name = "success", type = "redirect", location = "listComment?news=${news.getId()}"),
			@Result(name = "error", type = "chain", location = "editCommentChild?news=${news.getId()}") })
	public String saveChild() {
		this.commentChild.setTitle(comment.getNews().getTitle());
		if(upload!=null){
		this.commentChild.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.commentChild.setComment(comment);
		this.commentChildService.save(commentChild);
		return SUCCESS;
	}
	@Action(value = "saveChildNewsReceive", results = {
			@Result(name = "success", type = "redirect", location = "listCommentNewsReceive?newsReceive=${newsReceive.getId()}"),
			@Result(name = "error", type = "chain", location = "editCommentChildNewsReceive?newsReceive=${newsReceive.getId()}") })
	public String saveChildNewsReceive() {
		this.commentChild.setTitle(comment.getNewsReceive().getTitle());
		if(upload!=null){
		this.commentChild.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.commentChild.setComment(comment);
		this.commentChildService.save(commentChild);
		return SUCCESS;
	}
	@Action(value = "saveChildPicture", results = {
			@Result(name = "success", type = "redirect", location = "listCommentPictureNews?pictureNews=${pictureNews.getId()}"),
			@Result(name = "error", type = "chain", location = "editCommentChildPictureNews?pictureNews=${pictureNews.getId()}") })
	public String saveChildPicture() {
		this.commentChild.setTitle(comment.getPictureNews().getTitle());
		if(upload!=null){
		this.commentChild.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.commentChild.setComment(comment);
		this.commentChildService.save(commentChild);
		return SUCCESS;
	}
	@Action(value = "saveChildPictureReceive", results = {
			@Result(name = "success", type = "redirect", location = "listCommentPictureNewsReceive?pictureNewsReceive=${pictureNewsReceive.getId()}"),
			@Result(name = "error", type = "chain", location = "editCommentChildPictureNewsReceive?pictureNewsReceive=${pictureNewsReceive.getId()}") })
	public String saveChildPictureReceive() {
		this.commentChild.setTitle(comment.getPictureNewsReceive().getTitle());
		if(upload!=null){
		this.commentChild.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.commentChild.setComment(comment);
		this.commentChildService.save(commentChild);
		return SUCCESS;
	}
	@Action(value = "saveChildAnnouncement", results = {
			@Result(name = "success", type = "redirect", location = "listCommentAnnouncement?announcement=${announcement.getId()}"),
			@Result(name = "error", type = "chain", location = "editCommentChildAnnouncement?announcement=${announcement.getId()}") })
	public String saveChildAnnouncement() {
		this.commentChild.setTitle(comment.getAnnouncement().getTitle());
		if(upload!=null){
		this.commentChild.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.commentChild.setComment(comment);
		this.commentChildService.save(commentChild);
		return SUCCESS;
	}
	@Action(value = "saveChildAnnouncementReceive", results = {
			@Result(name = "success", type = "redirect", location = "listCommentAnnouncementReceive?announcementReceive=${announcementReceive.getId()}"),
			@Result(name = "error", type = "chain", location = "editCommentChildAnnouncementReceive?announcementReceive=${announcementReceive.getId()}") })
	public String saveChildAnnouncementReceive() {
		this.commentChild.setTitle(comment.getAnnouncementReceive().getTitle());
		if(upload!=null){
		this.commentChild.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.commentChild.setComment(comment);
		this.commentChildService.save(commentChild);
		return SUCCESS;
	}
	@Action(value = "saveChildNotice", results = {
			@Result(name = "success", type = "redirect", location = "listCommentNotice?notice=${notice.getId()}"),
			@Result(name = "error", type = "chain", location = "editCommentChildNotice?notice=${notice.getId()}") })
	public String saveChildNotice() {
		this.commentChild.setTitle(comment.getNotice().getTitle());
		if(upload!=null){
		this.commentChild.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.commentChild.setComment(comment);
		this.commentChildService.save(commentChild);
		return SUCCESS;
	}
	@Action(value = "saveChildNoticeAccept", results = {
			@Result(name = "success", type = "redirect", location = "listCommentNoticeAccept?noticeAccept=${noticeAccept.getId()}"),
			@Result(name = "error", type = "chain", location = "editCommentChildNoticeAccept?noticeAccept=${noticeAccept.getId()}") })
	public String saveChildNoticeAccept() {
		this.commentChild.setTitle(comment.getNoticeAccept().getTitle());
		if(upload!=null){
		this.commentChild.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.commentChild.setComment(comment);
		this.commentChildService.save(commentChild);
		return SUCCESS;
	}
	
	public Comment getComment() {
		return comment;
	}

	public void setComment(Comment comment) {
		this.comment = comment;
	}

	public CommentService getCommentService() {
		return commentService;
	}

	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}

	public Affiche getAffiche() {
		return affiche;
	}

	public void setAffiche(Affiche affiche) {
		this.affiche = affiche;
	}

	public List<CommentChild> getChilds() {
		return childs;
	}

	public void setChilds(List<CommentChild> childs) {
		this.childs = childs;
	}
	public CommentChild getCommentChild() {
		return commentChild;
	}
	public void setCommentChild(CommentChild commentChild) {
		this.commentChild = commentChild;
	}
	public CommentChildService getCommentChildService() {
		return commentChildService;
	}
	public void setCommentChildService(CommentChildService commentChildService) {
		this.commentChildService = commentChildService;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public String getChildNum() {
		return childNum;
	}
	public void setChildNum(String childNum) {
		this.childNum = childNum;
	}
	public News getNews() {
		return news;
	}
	public void setNews(News news) {
		this.news = news;
	}
	public NewsService getNewsService() {
		return newsService;
	}
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}
	public PictureNews getPictureNews() {
		return pictureNews;
	}
	public void setPictureNews(PictureNews pictureNews) {
		this.pictureNews = pictureNews;
	}
	public PictureNewsService getPictureNewsService() {
		return pictureNewsService;
	}
	public void setPictureNewsService(PictureNewsService pictureNewsService) {
		this.pictureNewsService = pictureNewsService;
	}
	public Announcement getAnnouncement() {
		return announcement;
	}
	public void setAnnouncement(Announcement announcement) {
		this.announcement = announcement;
	}
	public Notice getNotice() {
		return notice;
	}
	public void setNotice(Notice notice) {
		this.notice = notice;
	}
	public NoticeService getNoticeService() {
		return noticeService;
	}
	public void setNoticeService(NoticeService noticeService) {
		this.noticeService = noticeService;
	}
	public NoticeAccept getNoticeAccept() {
		return noticeAccept;
	}
	public void setNoticeAccept(NoticeAccept noticeAccept) {
		this.noticeAccept = noticeAccept;
	}
	public NoticeAcceptService getNoticeAcceptService() {
		return noticeAcceptService;
	}
	public void setNoticeAcceptService(NoticeAcceptService noticeAcceptService) {
		this.noticeAcceptService = noticeAcceptService;
	}
	
}
